//
//  Theme.m
//  planner
//
//  Created by 함동균 on 2014. 3. 13..
//  Copyright (c) 2014년 idea. All rights reserved.
//

#import "Theme.h"

@interface Theme()

@end

@implementation Theme

+ (NSDictionary *)tabMenuProperty:(NSString *)tabMenu
{
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    NSString *plistPath;
    NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                              NSUserDomainMask, YES) objectAtIndex:0];
    plistPath = [rootPath stringByAppendingPathComponent:@"Theme.plist"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
        plistPath = [[NSBundle mainBundle] pathForResource:@"Theme" ofType:@"plist"];
    }
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format
                                          errorDescription:&errorDesc];
    if (!temp) {
        NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
    }

    return [temp objectForKey:tabMenu];
}

+ (NSString *)stringProperty:(NSString *)property fromTabMenu:(NSString *)tabMenu
{
    NSDictionary *propertyList = [Theme tabMenuProperty:tabMenu];
    return [propertyList objectForKey:property];
}

+ (UIColor *)colorProperty:(NSString *)property fromTabMenu:(NSString *)tabMenu
{
    NSDictionary *propertyList = [Theme tabMenuProperty:tabMenu];
    NSDictionary *colorProperty = [propertyList objectForKey:property];
    return [UIColor colorWithRed:[[colorProperty objectForKey:COLOR_RED] floatValue] / 255.0f
                           green:[[colorProperty objectForKey:COLOR_GREEN] floatValue] / 255.0f
                            blue:[[colorProperty objectForKey:COLOR_BLUE] floatValue] / 255.0f
                           alpha:1.0f];
}
@end
